package com.romanito.andiview;

import java.io.File;

import android.net.Uri;
import android.webkit.MimeTypeMap;

public class ImageFile {
	private String _directory;
	private String _name;
	private String _mimeType;
	
	public ImageFile(String fullName)
	{
		if (fullName.contains("/"))
		{
			_directory = fullName.substring(0, fullName.lastIndexOf("/") - 1);
			_name = fullName.substring(fullName.lastIndexOf("/") + 1);
		}
		else
		{
			_name = fullName;
		}
	}
	
	public ImageFile(String directory, String name)
	{
		_directory = directory;
		_name = name;
	}
	
	public String getDirectory()
	{
		return _directory;
	}
	
	public void setDirectory(String value)
	{
		if (value.endsWith("/"))
			_directory = value.substring(0, value.length() - 2);
		else
			_directory = value;
	}

	public String getName()
	{
		return _name;
	}
	
	public String getFullName()
	{
		return _directory + "/" + _name;
	}
	
	public Uri getUri() {
		return Uri.fromFile(new File(getFullName()));
	}
	
	public String getExtension() {
		return _name.substring(_name.lastIndexOf('.') + 1);
	}
	
	public String getMimeType() {
		if (_mimeType == null) {
			MimeTypeMap mime = MimeTypeMap.getSingleton();
			_mimeType = mime.getMimeTypeFromExtension(getExtension());
		}
		return _mimeType;
	}
}
